package com.ruoyi.project.system.create.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.create.domain.LiveCreate;
import com.ruoyi.project.system.create.service.ILiveCreateService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 直播列表Controller
 * 
 * @author ruoyi
 * @date 2024-11-25
 */
@Controller
@RequestMapping("/system/create")
public class LiveCreateController extends BaseController
{
    private String prefix = "system/create";

    @Autowired
    private ILiveCreateService liveCreateService;

    @RequiresPermissions("system:create:view")
    @GetMapping()
    public String create()
    {
        return prefix + "/create";
    }

    /**
     * 查询直播列表列表
     */
    @RequiresPermissions("system:create:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LiveCreate liveCreate)
    {
        startPage();
        List<LiveCreate> list = liveCreateService.selectLiveCreateList(liveCreate);
        return getDataTable(list);
    }

    /**
     * 导出直播列表列表
     */
    @RequiresPermissions("system:create:export")
    @Log(title = "直播列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LiveCreate liveCreate)
    {
        List<LiveCreate> list = liveCreateService.selectLiveCreateList(liveCreate);
        ExcelUtil<LiveCreate> util = new ExcelUtil<LiveCreate>(LiveCreate.class);
        return util.exportExcel(list, "直播列表数据");
    }

    /**
     * 新增直播列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存直播列表
     */
    @RequiresPermissions("system:create:add")
    @Log(title = "直播列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LiveCreate liveCreate)
    {
        return toAjax(liveCreateService.insertLiveCreate(liveCreate));
    }

    /**
     * 修改直播列表
     */
    @RequiresPermissions("system:create:edit")
    @GetMapping("/edit/{roomId}")
    public String edit(@PathVariable("roomId") Long roomId, ModelMap mmap)
    {
        LiveCreate liveCreate = liveCreateService.selectLiveCreateByRoomId(roomId);
        mmap.put("liveCreate", liveCreate);
        return prefix + "/edit";
    }

    /**
     * 修改保存直播列表
     */
    @RequiresPermissions("system:create:edit")
    @Log(title = "直播列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LiveCreate liveCreate)
    {
        return toAjax(liveCreateService.updateLiveCreate(liveCreate));
    }

    /**
     * 删除直播列表
     */
    @RequiresPermissions("system:create:remove")
    @Log(title = "直播列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(liveCreateService.deleteLiveCreateByRoomIds(ids));
    }
}
